package com.epoint.mobileoa.tools;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.FrameMethod;
import com.epoint.mobileoa.bizlogic.SuperView;



import android.content.Context;
import android.widget.EditText;

/**
 * @author liyc
 * @time 2012-1-8 上午12:50:14
 * @annotation 
 */
public class StringHelp {

	public static boolean isLength0(String s){
		if(s.trim().length()==0){
			return true;
		}
		return false;
	}

	/**
	 * 获取XML标签之间的属性
	 * 如:
	 * bs = "<name>epoint</name>"
	 * att = "name"
	 * return "epoint"
	 */
	public static String getXMLAtt(String bs,String att){
		String result = "";
		try{
			String  head = "<"+att+">";
			String tail = "</"+att+">";
			result = bs.substring(bs.indexOf(head)+head.length(),bs.indexOf(tail));
		}catch(Exception e){
			e.printStackTrace();
			return "";
		}
		return result;
	}

	/**
	 * @author liyc
	 * @time 2012-3-6 上午10:31:32
	 * @annotation 获取标签如 xml = <root><outs><out>beijing</out></outs></root>
	 * bs = xml ,att = "outs"
	 * return <outs><out>beijing</out></outs>
	 */
	public static String getXMLAttOut(String bs,String att){
		String bs1 = getXMLAtt(bs, att);
		return "<"+att+">"+bs1+"</"+att+">";
	}

	public static String getAttOut(String bs,String att){
		String s = "";
		try{
			s = bs.substring(bs.indexOf("<"+att+">"), bs.indexOf("</"+att+">")+("</"+att+">").length());
		}catch(Exception e){
			e.printStackTrace();
		}
		return s;
	}

	public static String getHtmlFormat1(SuperView sv,String q,String h){
		return "<font color="+sv.getYGColor()+">"+q+"</font><font color="+sv.getBlackOrWhiteColor()+">"+h+"</font>";
	}

	public static String get2AttMid(String bs,String q,String h){
		return bs.substring(bs.indexOf(q)+q.length(),bs.indexOf(h));
	}

	//人员选择后List转字符串
	public static String[] dealChooseListToString(List<Map<String,String>> clst){
		String snname = "";
		String sguid = "";
		int size = clst.size();
		if(size>0){
			for(int i=0;i<size;i++){
				if(i<size-1){
					snname += clst.get(i).get("name")+";";
					sguid += clst.get(i).get("guid")+";";
				}
				else if(i==size-1){
					snname += clst.get(i).get("name");
					sguid += clst.get(i).get("guid");
				}
			}
		}
		String[] info = new String[2];
		info[0] = snname;
		info[1] = sguid;
		return info;
	}

	public static List<Map<String,String>> String2List(String names,String guids){
		List<Map<String,String>> list = new ArrayList<Map<String,String>>();
		if(names==null||guids==null||"".equals(names)||"".equals(guids)){
			return new ArrayList<Map<String,String>>();
		}
		String[] s_name = names.split(";");
		String[] s_guid = guids.split(";");
		for(int i=0;i<s_name.length;i++){
			Map<String,String> map = new HashMap<String, String>();
			map.put("name", s_name[i]);
			map.put("guid", s_guid[i]);
			list.add(map);
		}
		return list;
	}

	public static boolean isEditTextBlank(EditText et){
		if(et.getText().toString().trim().length()==0){
			return true;
		}
		else{
			return false;
		}
	}



	public  static String getSingleFaWenData(SuperView sv,String title,String content){
		if(content.equals("")){
			return "";
		}
		return "<font size=2 color="+sv.getYGColor()+">"+title+"</font><font size=2 color="+sv.getBlackOrWhiteColor()+">"+content+"</font><hr color=blue/>";
	}
	
	public  static String getFormInfoHtml(SuperView sv,String title,String content){
		content = content==null?"":content;
//		if(content.equals("")){
//			return "";
//		}
		return "<font size=2 color="+sv.getYGColor()+">"+title+"：</font><font size=2 color="+sv.getBlackOrWhiteColor()+">"+content+"</font><hr color=blue/>";
	}
	
	public  static String getProcessHtml(SuperView sv,String title,String content){
		/*if(content.equals("")){
			return "";
		}*/
		return "<font size=2 color="+sv.getYGColor()+">"+title+"</font><font size=2 color="+sv.getBlackOrWhiteColor()+">"+content+"</font><br/>";
	}
	
	public  static String getProcessHtml2(SuperView sv,String title,String content){
		/*if(content.equals("")){
			return "";
		}*/
		return "<font size=2 color=yellow>"+title+"</font><font size=2 color=white>"+content+"</font><br/>";
	}

	public static String getResSeamUrl(Context con){
		return con.getString(R.string.http)+con.getString(R.string.ip)+"/"+con.getString(R.string.interfacename)+"/"+con.getString(R.string.interfacepage);
	}
	
	public static String getMsiUrl(SuperView con){
		return con.getString(R.string.http)+FrameMethod.getIp(con.fp, con)+"/"+con.getString(R.string.interfacename)+"/"+con.getString(R.string.msipage);
	}
	
	public static boolean isEqualBlank(String s){
		s = s==null?"":s;
		if(s.equals("")){
			return true;
		}
		return false;
	}
	
	/**
	 * 截除字符串最后一个标志，如abc;，将末尾;截去
	 * @param s 原始字符
	 * @param Symbol 结尾需要截取的字符
	 * @return 截除完成的字符
	 */
	public static String cutLastSymbol(String s,String Symbol)
	{
		if(s.endsWith(Symbol))
		{
			return s.substring(0, s.length()-1);
		}
		return s;
	}
}
